package com.superitem.school.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.superitem.school.mapper.UserMapper;
import com.superitem.school.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {

    @Autowired(required = false)
    UserMapper userMapper;

    public User queryById(Long id){
        return userMapper.selectByPrimaryKey(id);
    }

    public int userUpdate(User user){
        return userMapper.updateByPrimaryKey(user);
    }

    public int userSave(User user){
        return userMapper.insertSelective(user);
    }

    public PageInfo<User> selectAllUser(Integer PageNum, Integer pageSize){
        PageHelper.startPage(PageNum, pageSize);
        List<User> users = userMapper.selectAll();
        return new PageInfo<>(users);
    }

    public int deleteUserById(Integer id){
        return userMapper.deleteByPrimaryKey(id);
    }
}